//
//  MCGongXiangViewController.m
//  XDYL
//
//  Created by menhao on 2018/3/30.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCGongXiangViewController.h"
#import "MCSharePoolModel.h"
#import "MCSharePoolBtnModel.h"
@interface MCGongXiangViewController ()

@property (nonatomic,weak) UILabel *moneyTileLabel;
@property (nonatomic,weak) UILabel *titleDateLabel;
@property (nonatomic,weak) UILabel *personCountDetailLabel;
@property (nonatomic,weak) UILabel *guizeMoneyLabel;
@property (nonatomic,weak) UIButton *btn;
@property (nonatomic,strong) MCSharePoolModel *sharePoolModel;
@property (nonatomic,strong) MCSharePoolBtnModel *sharePoolbtnModel;
@end

@implementation MCGongXiangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
    self.navigationItem.title = @"共享经济";
    [self loadData];
}
-(void)setUpUI{
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = RGB(245, 245, 245);
    UIScrollView *bases = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bases];
    
    bases.contentSize = CGSizeMake(G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT + 300);
    UIImageView *titleImageV = [[UIImageView alloc] init];
    [bases addSubview:titleImageV];
    titleImageV.image = [UIImage imageNamed:@"gongxiangtu"];
    
    [titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bases).offset(13);
        make.width.equalTo(@(G_SCREENWIDTH - MC_REALVALUE(26)));
        make.height.equalTo(@(130));
        make.top.equalTo(bases).offset(13);
        
    }];
    UILabel *titleLabel =  [[UILabel alloc] init];
    [bases addSubview:titleLabel];
    titleLabel.text = @"当前奖池累计：";
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = RGB(138, 138, 138);
    titleLabel.font = [UIFont boldSystemFontOfSize:MC_REALVALUE(16)];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleImageV).offset(MC_REALVALUE(17));
        make.top.equalTo(titleImageV.mas_bottom).offset(MC_REALVALUE(52));
        
    }];
    
    UILabel *moneyTileLabel =  [[UILabel alloc] init];
    [bases addSubview:moneyTileLabel];
    moneyTileLabel.textAlignment = NSTextAlignmentLeft;
    moneyTileLabel.text = @"0";
    self.moneyTileLabel = moneyTileLabel;
    moneyTileLabel.textColor = RGB(0, 0, 0);
    moneyTileLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(23)];
    [moneyTileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleImageV).offset(MC_REALVALUE(-32));
        make.centerY.equalTo(titleLabel);
        
    }];
    
    UILabel *unitTileLabel =  [[UILabel alloc] init];
    [bases addSubview:unitTileLabel];
    unitTileLabel.textAlignment = NSTextAlignmentLeft;
    unitTileLabel.text = @"元";
    
    unitTileLabel.textColor = RGB(0, 0, 0);
    unitTileLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(16)];
    [unitTileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleImageV).offset(MC_REALVALUE(-16));
        make.centerY.equalTo(titleLabel);
        
    }];
    
    UILabel *titleSubLabel =  [[UILabel alloc] init];
    [bases addSubview:titleSubLabel];
    titleSubLabel.textAlignment = NSTextAlignmentLeft;
    titleSubLabel.text = @"统计区间:";
    titleSubLabel.textColor = RGB(138, 138, 138);
    titleSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(16)];
    [titleSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset(MC_REALVALUE(47));
        
    }];
    
    
    UILabel *titleDateLabel =  [[UILabel alloc] init];
    [bases addSubview:titleDateLabel];
    titleDateLabel.text = @"暂无";
    titleDateLabel.textColor = RGB(0, 0, 0);
    titleDateLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.titleDateLabel = titleDateLabel;
    [titleDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleImageV).offset(MC_REALVALUE(-16));
        make.centerY.equalTo(titleSubLabel);
    }];
    
    
    UILabel *personCountLabel =  [[UILabel alloc] init];
    [bases addSubview:personCountLabel];
    personCountLabel.text = @"分奖人数：";
    personCountLabel.textAlignment = NSTextAlignmentLeft;
    personCountLabel.textColor = RGB(138, 138, 138);
    personCountLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(16)];
    [personCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleSubLabel);
        make.top.equalTo(titleSubLabel.mas_bottom).offset(MC_REALVALUE(48));
        
    }];
    
    UILabel *personCountDetailLabel =  [[UILabel alloc] init];
    [bases addSubview:personCountDetailLabel];
    personCountDetailLabel.numberOfLines = 0;
    personCountDetailLabel.text = @"暂无";
    self.personCountDetailLabel = personCountDetailLabel;
    personCountDetailLabel.textAlignment = NSTextAlignmentLeft;
    personCountDetailLabel.textColor = RGB(0, 0, 0);
    personCountDetailLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(17)];
    [personCountDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleImageV).offset(MC_REALVALUE(-16));
        make.centerY.equalTo(personCountLabel);
        
        
    }];
    
    
    
    UILabel *guizeLabel =  [[UILabel alloc] init];
    [bases addSubview:guizeLabel];
    guizeLabel.text = @"预计我可以分到：";
    guizeLabel.textAlignment = NSTextAlignmentLeft;
    guizeLabel.textColor = RGB(138, 138, 138);
    guizeLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(16)];
    [guizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(personCountLabel);
        make.top.equalTo(personCountLabel.mas_bottom).offset(MC_REALVALUE(48));
        
    }];
    
    
    UILabel *guizeMoneyLabel =  [[UILabel alloc] init];
    [bases addSubview:guizeMoneyLabel];
    self.guizeMoneyLabel = guizeMoneyLabel;
    guizeMoneyLabel.text = @"0";
    guizeMoneyLabel.textAlignment = NSTextAlignmentLeft;
    guizeMoneyLabel.textColor = RGB(202, 39, 68);
    guizeMoneyLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(21)];
    [guizeMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleImageV).offset(MC_REALVALUE(-32));
        make.centerY.equalTo(guizeLabel);
        
    }];
    
    
    UILabel *unitMTileLabel =  [[UILabel alloc] init];
    [bases addSubview:unitMTileLabel];
    unitMTileLabel.textAlignment = NSTextAlignmentLeft;
    unitMTileLabel.text = @"元";
    unitMTileLabel.textColor = RGB(0, 0, 0);
    unitMTileLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(16)];
    [unitMTileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleImageV).offset(MC_REALVALUE(-16));
        make.centerY.equalTo(guizeMoneyLabel);
        
    }];
    UIButton *btn = [[UIButton alloc] init];
    [bases addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bases);
        make.bottom.equalTo(unitMTileLabel.mas_bottom).offset(MC_REALVALUE(140));
        make.height.equalTo(@(53));
        make.width.equalTo(@(169));
    }];
    
    [btn setImage:[UIImage imageNamed:@"领取"] forState:UIControlStateNormal];
    
    [btn addTarget:self action:@selector(btnCLick) forControlEvents:UIControlEventTouchUpInside];
    self.btn = btn;
    btn.hidden = YES;
    
}
- (void)loadData{
    
    MCSharePoolModel *sharePoolModel = [[MCSharePoolModel alloc] init];
    self.sharePoolModel = sharePoolModel;
    [sharePoolModel refreashDataAndShow];
    [BKIndicationView showInView:self.view];
    __weak typeof(self) weakself= self;
    sharePoolModel.callBackSuccessBlock = ^(ApiBaseManager *manager) {
        [BKIndicationView dismiss];
        if (manager.ResponseRawData != nil) {
            weakself.moneyTileLabel.text = [NSString stringWithFormat:@"%@",manager.ResponseRawData[@"SumMoney"]];
            weakself.titleDateLabel.text =[NSString stringWithFormat:@"%@至%@",manager.ResponseRawData[@"BeginTime"],manager.ResponseRawData[@"EndTime"]];
            weakself.personCountDetailLabel.text = [NSString stringWithFormat:@"%@",manager.ResponseRawData[@"UserCount"]];
            weakself.guizeMoneyLabel.text = [NSString stringWithFormat:@"%@",manager.ResponseRawData[@"OriginalReward"]];
            NSString *str =  [NSString stringWithFormat:@"%@",manager.ResponseRawData[@"IsEnable"]];
            if ([str isEqualToString:@"0"]) {
                weakself.btn.hidden = YES;
            } else {
                weakself.btn.hidden = NO;
            }
        }
        
        
    };
    sharePoolModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        [BKIndicationView dismiss];
        
    };
    
}
- (void)btnCLick{
    
    MCSharePoolBtnModel *sharePoolbtnModel = [[MCSharePoolBtnModel alloc] init];
    self.sharePoolbtnModel = sharePoolbtnModel;
    [sharePoolbtnModel refreashDataAndShow];
    [BKIndicationView showInView:self.view];
    __weak typeof(self) weakself= self;
    sharePoolbtnModel.callBackSuccessBlock = ^(ApiBaseManager *manager) {
        [SVProgressHUD showInfoWithStatus:manager.ResponseRawData[@"Msg"]];
        [weakself loadData];
        
    };
    
    sharePoolbtnModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        [SVProgressHUD showInfoWithStatus:manager.responseMessage];
        weakself.btn.hidden = NO;
        
    };
}
@end



